﻿@page "/"
@using ProjectTracker.Library
@inject Csla.Blazor.ViewModel<Dashboard> vm

<h1>Project Tracker</h1>

<p>Welcome to the project tracker sample app.</p>

<p class="text-danger">@vm.ViewModelErrorText</p>
<p class="text-danger">@ErrorText</p>

@if (vm.Model != null)
{
  <table>
    <tbody>
      <tr><td>Projects</td><td>@vm.Model.ProjectCount</td></tr>
      <tr><td>Open projects</td><td>@vm.Model.OpenProjectCount</td></tr>
      <tr><td>Resources</td><td>@vm.Model.ResourceCount</td></tr>
    </tbody>
  </table>
}
else
{
  <p>Loading data...</p>
}

@code {
  private string ErrorText;

  protected override async Task OnParametersSetAsync()
  {
    try
    {
      await vm.RefreshAsync(() => Csla.DataPortal.FetchAsync<Dashboard>());
    }
    catch (Exception ex)
    {
      ErrorText = ex.Message;
    }
  }
}
